#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    string reverseWords(string s) {
        int begin = 0;
        int end = 0;
        for (int i = 0; i < s.size(); i++)
        {
            if (s[i] == ' ')
            {
                end = i;
                reverse(s.begin() + begin, s.begin() + end);
                begin = end + 1;

            }
        }
        reverse(s.begin() + begin, s.end());
        return s;
    }
};